﻿
Pharaphernalia = {
    PharaphernaliaUpdatePopUpId: '',
    CurrentRow: null,
    OnAddPharaphernaliaClick: function () {
        $('#btnAddPharaphernalia').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("id");
            Pharaphernalia.PharaphernaliaUpdatePopUpId = id;

            PopUpDialog.UrlDialog("Pharaphernalia", 420, 280, true, "../PopupBoxes/PharaphernaliaDialogBox.aspx?id=0", id);

        });
    },
    OnUpdatePharaphernaliaClick: function () {
        $('table#Pharaphernaliatbl .btnUdpate').live("click", function (e) {
            e.preventDefault();
            var id = $(this).attr("data-id");
            Pharaphernalia.CurrentRow = $(this).closest("tr");
            Pharaphernalia.PharaphernaliaUpdatePopUpId = id;

            PopUpDialog.UrlDialog("Pharaphernalia", 420, 280, true, "../PopupBoxes/PharaphernaliaDialogBox.aspx?id=" + id, id);
        });
    },
    OnDeletePharaphernaliaClick: function () {
        $('table#Pharaphernaliatbl .btnDelete').live("click", function (e) {
            e.preventDefault();
            if (confirm('Are you sure you want to delete item?')) {
                var id = $(this).attr("data-id");
                var json = JSON.stringify({ Id: id });
                Pharaphernalia.CurrentRow = $(this).closest("tr");
                $.ajax({
                    type: "POST",
                    url: "../Webservices/UtilitiesWebsService.asmx/DeletePharaphernalia",
                    data: json,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        var response = eval('(' + data.d + ')');
                        if (response.Success) {
                            Pharaphernalia.CurrentRow.remove();                            
                        }
                    }
                });

            }
        });
    },
    SetRowData: function (Obj) {
        if (Obj.IsAdded) {
            location.reload(true);
        }
        var id = Obj.PPItem.Id;
        var description = Obj.PPItem.Description;
        var amount = Obj.PPItem.Amount;

        Pharaphernalia.CurrentRow.find("td").eq(0).html(id);
        Pharaphernalia.CurrentRow.find("td").eq(1).html(description);
        Pharaphernalia.CurrentRow.find("td").eq(2).html(amount);
    }
}

$(document).ready(function () {
    Pharaphernalia.OnAddPharaphernaliaClick();
    Pharaphernalia.OnUpdatePharaphernaliaClick();
    Pharaphernalia.OnDeletePharaphernaliaClick();    
});